package com.zkingsoft.services.impl;

import com.zkingsoft.services.ReportService;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.model.Report;
import com.zkingsoft.model.SendReport;
import com.zkingsoft.constance.Dictionary;
import com.zkingsoft.dao.ReportDao;
import com.zkingsoft.dao.SendReportDao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-11 10:23
 */
@Service("reportService")
public class  ReportServiceImpl implements    ReportService  {

	
	@Autowired
	private ReportDao reportDao;
	@Autowired
	private SendReportDao sendReportDao;
	
	@Transactional
	@Override
	public int add(Report report){
		int i = reportDao.insert(report);
		
		String receiveId = report.getReceiveId();
		while(receiveId.length()>1){
			Long userId=Long.parseLong(receiveId.substring(0,receiveId.indexOf(",")));
			receiveId=receiveId.substring(receiveId.indexOf(",")+1, receiveId.length());
			SendReport sendReport=new SendReport();
			sendReport.setReceiveId(userId);
			sendReport.setStatus(Dictionary.SENDREPORT_STATUS_WYD);
			sendReport.setReportId(report.getId());
			sendReportDao.insert(sendReport);
		}
		
		
		return i;
		
	}
   	
    @Override
	public int modify(Report report){
	
		return reportDao.update(report);
	
	}
    @Transactional
	@Override
	public int remove(List<Long> list){
		for(Long id:list){
			SendReport sendReport=new SendReport();
			sendReport.setReportId(id);
			sendReportDao.deleteByModel(sendReport);
		}
		return reportDao.deleteByIds(list);
	
	}
	@Transactional
	@Override
	public int removeById(Long id){
		SendReport sendReport=new SendReport();
		sendReport.setReportId(id);
		sendReportDao.deleteByModel(sendReport);
		return reportDao.deleteById(id);
	
	}
	
	@Override
	public int removeByModel(Report report){
	
		return reportDao.deleteByModel(report);
	
	}
	
	
	@Override
	public List<Report> findInPage(Report report,  PaginationVO pageVo){
	
		return reportDao.selectInPage(report , pageVo);
	
	}
	
	@Override
	public List<Report> findByModel(Report report){
	
		return reportDao.selectByModel(report);
	
	}
	
	@Override
	public int  findTotal(Report report){
	
		return reportDao.selectTotalRecord(report);
	
	}
	
	@Override
	public Report  findById(Long id){
	
		return reportDao.selectById(id);
	
	}

   	
	
	
}